package com.beta.admin.controller;

import com.beta.admin.support.web.BaseController;
import com.beta.em.admins.BankAccountType;
import com.beta.entity.BankAccounts;
import com.beta.service.IBankAccountsService;
import com.beta.admin.vo.BankAccountTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lichao on 2017/1/19.
 */
@RestController
@RequestMapping(value = RequestMappingConstants.MAPPING_PREFIX + "/bank_accounts")
public class BankController extends BaseController {
    @Autowired
    private IBankAccountsService bankAccountsService;
    @GetMapping("/{id}")
    public Object getBankAccounts(@PathVariable("id")Integer userId){
        BankAccounts bankAccounts = bankAccountsService.getBankAccounts(userId);
        return ok(bankAccounts);
    }
    @GetMapping("/account_types")
    public Object getAccountType(){
        BankAccountType[] types = BankAccountType.values();
        List<BankAccountTypeVo> accountTypes=new ArrayList<BankAccountTypeVo>();
        for (BankAccountType type:types) {
            BankAccountTypeVo bankAccountTypeVo=new BankAccountTypeVo();
            bankAccountTypeVo.setValue(type.getValue());
            bankAccountTypeVo.setName(type.getCnValue());
            accountTypes.add(bankAccountTypeVo);
        }
        return ok(accountTypes);
    }
}
